package cn.wolfcode.service.impl;

import cn.wolfcode.domain.SystemDictionary;
import cn.wolfcode.mapper.SystemDictionaryMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.SystemDictionaryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryServiceImpl implements SystemDictionaryService {

    private SystemDictionaryMapper systemDictionaryMapper;
    @Autowired
    public void setSystemDictionaryMapper(SystemDictionaryMapper systemDictionaryMapper) {
        this.systemDictionaryMapper = systemDictionaryMapper;
    }

    @Override
    public PageInfo<SystemDictionary> listPage(QueryObject queryObject) {
        //使用分页插件，PageInfo类封装了很多i我们之前封装的信息，
        // applicationContext.xml还配置拦截器，对sql进行拦截，拼接limit

        //1.使用分页插件，不需要写limit会帮我们进行拦截sql，进行拼接
        //2.不需要封装开始的页数StartPage
        //3.不需要封装结果集
        //4.不需要写count语句，自动生成

        //传入参数，初始化pageInfo对象的当前页，页面数量信息，表示开始分页
        PageHelper.startPage(queryObject.getCurrentPage(),queryObject.getPageSize());
        //通过拦截器，拿到方法对应的sql，进行limit和之前的两个参数进行拼接
        List<SystemDictionary> systemDictionarys = systemDictionaryMapper.listPage(queryObject);
        return new PageInfo<>(systemDictionarys);  //内部计算下一页，上一页，总页数，设置data数据
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return systemDictionaryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(SystemDictionary record) {
        return systemDictionaryMapper.insert(record);
    }

    @Override
    public SystemDictionary selectByPrimaryKey(Long id) {
        return systemDictionaryMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SystemDictionary> selectAll() {
        return systemDictionaryMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(SystemDictionary record) {
        return systemDictionaryMapper.updateByPrimaryKey(record);
    }


}
